package com.example.rbacmanage.controller;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.ParamSetting;
import com.example.rbacmanage.service.ParamSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/paramsetting")
public class ParamSettingController {
    @Autowired
    private ParamSettingService paramSettingService;

    @GetMapping("/page")
    public Result page(ParamSetting paramSetting){
        return Result.success(paramSettingService.getPage(paramSetting));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable(value = "id") Long id){
        return Result.success(paramSettingService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('system:paramsetting:add')")
    @PostMapping("/add")
    public Result save(@RequestBody ParamSetting paramSetting){
        paramSettingService.save(paramSetting);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:paramsetting:update')")
    @PutMapping("/update")
    public Result update(@RequestBody ParamSetting paramSetting){
        paramSettingService.update(paramSetting);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:paramsetting:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        paramSettingService.remove(ids);
        return Result.success();
    }
}
